home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- child.c
-
- This module manages the parent/child window relationship
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include "glob.h"
- #include "child.h"
- #include "memutil.h"
-
-
-
- /*----------------------------------------------------------------------------
- AddChild
-
- Add a child window to the child window list of a parent window.
-
- Entry: parent = pointer to parent window.
- child = pointer to child window.
-
- Exit: function result = error code.
- ----------------------------------------------------------------------------*/
-
- OSErr AddChild (WindowPtr parent, WindowPtr child)
- {
- TWindow **parentInfo;
- TChild **newChild;
- OSErr err = noErr;
-
- parentInfo = (TWindow**) GetWRefCon(parent);
-
- err = MyNewHandle(sizeof(TChild), &newChild);
- if (err != noErr) return err;
- (**newChild).childWindow = child;
- (**newChild).next = (**parentInfo).childList;
- (**parentInfo).childList = newChild;
- return noErr;
- }
-
-
-
- /*----------------------------------------------------------------------------
- RemoveChild
-
- Remove a child window from the child window list of a parent window.
-
- Entry: parent = pointer to parent window.
- child = pointer to child window.
- ----------------------------------------------------------------------------*/
-
- void RemoveChild (WindowPtr parent, WindowPtr child)
- {
- TWindow **parentInfo;
- TChild **current, **prev;
-
- if (parent == nil) return;
- parentInfo = (TWindow**) GetWRefCon(parent);
- for (current = prev = (**parentInfo).childList;
- current != nil && (**current).childWindow != child;
- prev = current, current = (**current).next) /* do nothing */;
- if (current != nil) {
- if (prev == current) {
- (**parentInfo).childList = (**current).next;
- } else {
- (**prev).next = (**current).next;
- }
- MyDisposeHandle(current);
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- FindChildByIndex
-
- Locate a child window from an index in a group or subject array.
-
- Entry: wind = pointer to group or subject window.
- index = index in group or subject array.
-
- Exit: function result = pointer to child window, or nil if none.
- ----------------------------------------------------------------------------*/
-
- WindowPtr FindChildByIndex (WindowPtr wind, short index)
- {
- TWindow **info, **childInfo;
- TChild **childListRec;
- WindowPtr child;
- TWindowKind kind;
-
- info = (TWindow**)GetWRefCon(wind);
- kind = (**info).kind;
- for (childListRec = (**info).childList; childListRec != nil;
- childListRec = (**childListRec).next)
- {
- child = (**childListRec).childWindow;
- childInfo = (TWindow**)GetWRefCon(child);
- if (kind == kSubject) {
- if ((**childInfo).parentSubject == index) return child;
- } else {
- if ((**childInfo).parentGroup == index) return child;
- }
- }
- return nil;
- }
-
-
-
- /*----------------------------------------------------------------------------
- FindChild
-
- Locate a child window from a cell in a group or subject window list.
-
- Entry: wind = pointer to group or subject window.
- theCell = the cell in the window list.
-
- Exit: function result = pointer to child window, or nil if none.
- ----------------------------------------------------------------------------*/
-
- WindowPtr FindChild (WindowPtr wind, Cell theCell)
- {
- TWindow **info;
- ListHandle theList;
- short index, cellDataLen;
-
- info = (TWindow**)GetWRefCon(wind);
- theList = (**info).theList;
- cellDataLen = 2;
- LGetCell(&index, &cellDataLen, theCell, theList);
- return FindChildByIndex(wind, index);
- }
-